#include "BSP_Delay.h"

uint32_t DelayTimeCount; /**< 延时用计数变量 */
uint32_t TickTimeDiV = 1000; /**< 系统时钟分频系数 */


/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
	DelayTimeCount--;
}

/**
  * @brief  延时函数
  * @param[in] DelayTime 延时长度(单位：ms)
  * @retval None
  */
void delay(uint32_t DelayTime)
{
	DelayTimeCount = DelayTime*TickTimeDiV/1000;
	while(DelayTimeCount);
}

/**
  * @brief 延时初始化
  * @param[in] timediv 系统时钟分频，1000=1/1000 s
  * @retval None
  */
STATUS DelayInit(int timediv)
{
    TickTimeDiV = timediv;
    if (SysTick_Config(SystemCoreClock / TickTimeDiV))
	{ 
    /* Capture error */     
		while (1);
	}
    return ok;
}
